import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app_05/utils/MyTheme.dart';
import 'package:flutter_app_05/utils/ScreenAdapter.dart';
import 'package:flutter_app_05/widget/sdk_extens.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:fluttertoast/fluttertoast.dart';


class SetUpPage extends StatefulWidget {
  @override
  SetUpPagePageState createState() => new SetUpPagePageState();
}

class SetUpPagePageState extends State<SetUpPage> {
  var cir = Radius.circular(10.0);
  int tiji=0;
  int weights=0;
  int hot=0;
  int yali=0;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    init();

  }

  Future init()async{
    SharedPreferences prefs = await SharedPreferences.getInstance();

    tiji=prefs.getInt("tiji")??0;
    weights=prefs.getInt("weights")??0;
    hot=prefs.getInt("hot")??0;
    yali=prefs.getInt("yali")??0;
    setState(() {

    });
  }
  BuildContext mContext;
  @override
  Widget build(BuildContext context) {
    ScreenAdapter.init(context);
    mContext=context;

//    leading: IconButton(
//            icon: 'images/left_icon.png'.getImage(
//              width: 40,
//              height: 40,
//            ),
//            onPressed: () {
//              Navigator.pop(context);
//            }),

    return Scaffold(
      backgroundColor:  MyTheme(mContext).getColor('bg'),
      resizeToAvoidBottomInset: false,
      appBar: AppBar(
        centerTitle: true,
        leading: IconButton(
            color: MyTheme(context).getColor('colorBlack'),
            icon: Icon(Icons.arrow_back_ios),
            onPressed: () {
              Navigator.pop(context);
            }),
      ),
      body:Container(
        height: double.infinity,
        child:Stack(
          children: [
            Positioned(
              child: SingleChildScrollView(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      child: Text(
                        "请设置你的常用单位",
                        style: TextStyle(fontSize: 25, fontWeight: FontWeight.w800,color: MyTheme(mContext).getColor('colorBlack')),
                      ),
                      margin: EdgeInsets.only(left: 10.0, top: 10.0),
                    ),
                    Container(
                      alignment: Alignment.bottomCenter,
                      margin: EdgeInsets.all(10.0),
                      height: ScreenAdapter.height(172.0),
                      decoration: new BoxDecoration(
                          color: MyTheme(context).getColor('white'),
                          borderRadius: new BorderRadius.circular((10.0))),
                      child: Column(
                        children: [
                          Expanded(
                              child: Container(
                                margin: EdgeInsets.only(top: 10.0),
                                child: Text(
                                  "体积",
                                  style:
                                  TextStyle(fontSize: 20, fontWeight: FontWeight.w800,
                                    color: MyTheme(context).getColor('colorBlack'),
                                  ),
                                ),
                              )),
                          //
                          Expanded(
                              child: Row(
                                children: [
                                  Expanded(
                                    child: GestureDetector(
                                      child: Container(
                                        alignment: Alignment.center,
                                        decoration: new BoxDecoration(
                                            color: tiji==0?Colors.green:Color.fromARGB(1,242, 241, 247),
                                            borderRadius: new BorderRadius.only(
                                                bottomLeft: cir)),
                                        child: Text(
                                          "立方米",
                                          style:
                                          TextStyle(fontSize: 20, fontWeight: FontWeight.w800,color: tiji==0?Colors.white70: MyTheme(context).getColor('colorBlack')),
                                        ),
                                      ),

                                      onTap: () {
                                        tiji=0;
                                        setState(() {

                                        });
                                      },
                                    ),
                                  ),
                                  Expanded(
                                    child: GestureDetector(
                                      child: Container(
                                        alignment: Alignment.center,
                                        decoration: new BoxDecoration(
                                            color: tiji==1?Colors.green:Color.fromARGB(1,242, 241, 247),
                                            borderRadius: new BorderRadius.only(bottomRight: cir)),
                                        child: Text(
                                          "升",
                                          style:
                                          TextStyle(fontSize: 20, fontWeight: FontWeight.w800,color: tiji==1?Colors.white70:MyTheme(context).getColor('colorBlack')),
                                        ),
                                      ),
                                      onTap: (){
                                        tiji=1;
                                        setState(() {

                                        });
                                      },
                                    ),
                                  ),
                                ],
                              )),
                        ],
                      ),
                    ),
                    Container(
                      alignment: Alignment.bottomCenter,
                      margin: EdgeInsets.all(10.0),
                      height: ScreenAdapter.height(172.0),
                      decoration: new BoxDecoration(
                          color: MyTheme(context).getColor('white'),
                          borderRadius: new BorderRadius.circular((10.0))),
                      child: Column(
                        children: [
                          Expanded(
                              child: Container(
                                margin: EdgeInsets.only(top: 10.0),
                                child: Text(
                                  "重量",
                                  style:
                                  TextStyle(fontSize: 20, fontWeight: FontWeight.w800,
                                  ),
                                ),
                              )),
                          //
                          Expanded(
                              child: Row(
                                children: [
                                  Expanded(
                                    child: GestureDetector(
                                      child: Container(
                                        alignment: Alignment.center,
                                        decoration: new BoxDecoration(
                                            color: weights==0?Colors.green:Color.fromARGB(1,242, 241, 247),
                                            borderRadius: new BorderRadius.only(
                                                bottomLeft: cir)),
                                        child: Text(
                                          "千克",
                                          style:
                                          TextStyle(fontSize: 20, fontWeight: FontWeight.w800,color: weights==0?Colors.white70:MyTheme(context).getColor('colorBlack')),
                                        ),
                                      ),

                                      onTap: () {
                                        weights=0;
                                        setState(() {

                                        });
                                      },
                                    ),
                                  ),
                                  Expanded(
                                    child: GestureDetector(
                                      child: Container(
                                        alignment: Alignment.center,
                                        decoration: new BoxDecoration(
                                            color: weights==1?Colors.green:Color.fromARGB(1,242, 241, 247),
                                            borderRadius: new BorderRadius.only(
                                                bottomRight: cir)),
                                        child: Text(
                                          "吨",
                                          style:
                                          TextStyle(fontSize: 20, fontWeight: FontWeight.w800,color: weights==1?Colors.white70:MyTheme(context).getColor('colorBlack')),
                                        ),
                                      ),
                                      onTap: (){
                                        weights=1;
                                        setState(() {

                                        });
                                      },
                                    ),
                                  ),
                                ],
                              )),
                        ],
                      ),
                    ),
                    Container(
                      alignment: Alignment.bottomCenter,
                      margin: EdgeInsets.all(10.0),
                      height: ScreenAdapter.height(172.0),
                      decoration: new BoxDecoration(
                          color: MyTheme(context).getColor('white'),
                          borderRadius: new BorderRadius.circular((10.0))),
                      child: Column(
                        children: [
                          Expanded(
                              child: Container(
                                margin: EdgeInsets.only(top: 10.0),
                                child: Text(
                                  "热量",
                                  style:
                                  TextStyle(fontSize: 20, fontWeight: FontWeight.w800,
                                  ),
                                ),
                              )),

                          Expanded(
                              child: Row(
                                children: [
                                  Expanded(
                                    child: GestureDetector(
                                      child: Container(
                                        alignment: Alignment.center,
                                        decoration: new BoxDecoration(
                                            color: hot==0?Colors.green:Color.fromARGB(1,242, 241, 247),
                                            borderRadius: new BorderRadius.only(
                                                bottomLeft: cir)),
                                        child: Text(
                                          "GJ",
                                          style:
                                          TextStyle(fontSize: 20, fontWeight: FontWeight.w800,color: hot==0?Colors.white70:MyTheme(context).getColor('colorBlack')),
                                        ),
                                      ),

                                      onTap: () {
                                        hot=0;
                                        setState(() {

                                        });
                                      },
                                    ),
                                  ),
                                  SizedBox(height: 20,width:2.0,),
                                  Expanded(
                                    child: GestureDetector(
                                      child: Container(
                                        alignment: Alignment.center,
                                        decoration: BoxDecoration(
                                            color: hot==1?Colors.green:Color.fromARGB(1,242, 241, 247),
                                            borderRadius: new BorderRadius.only(
                                                bottomRight: cir)
                                        ),
                                        child: Text(
                                          "KWH",
                                          style:
                                          TextStyle(fontSize: 20, fontWeight: FontWeight.w800,color: hot==1?Colors.white70:MyTheme(context).getColor('colorBlack')),
                                        ),
                                      ),
                                      onTap: (){
                                        hot=1;
                                        setState(() {

                                        });
                                      },
                                    ),
                                  ),
                                ],
                              )),
                        ],
                      ),
                    ),
                    Container(
                      alignment: Alignment.bottomCenter,
                      margin: EdgeInsets.all(10.0),
                      height: ScreenAdapter.height(172.0),
                      decoration: new BoxDecoration(
                          color: MyTheme(context).getColor('white'),
                          borderRadius: new BorderRadius.circular((10.0))),
                      child: Column(
                        children: [
                          Expanded(
                              child: Container(
                                margin: EdgeInsets.only(top: 10.0),
                                child: Text(
                                  "压力",
                                  style:
                                  TextStyle(fontSize: 20, fontWeight: FontWeight.w800,
                                  ),
                                ),
                              )),

                          Expanded(
                              child: Row(
                                children: [
                                  Expanded(
                                    child: GestureDetector(
                                      child: Container(
                                        alignment: Alignment.center,
                                        decoration: new BoxDecoration(
                                            color: yali==0?Colors.green:Color.fromARGB(1,242, 241, 247),
                                            borderRadius: new BorderRadius.only(
                                                bottomLeft: cir)),
                                        child: Text(
                                          "Kpa",
                                          style:
                                          TextStyle(fontSize: 20, fontWeight: FontWeight.w800,color: yali==0?Colors.white70:MyTheme(context).getColor('colorBlack')),
                                        ),
                                      ),
                                      onTap: (){
                                        yali=0;
                                        setState(() {

                                        });
                                      },
                                    ),
                                  ),

                                  SizedBox(height: 20,width:2.0,),
                                  Expanded(
                                    child: GestureDetector(
                                      child: Container(
                                        alignment: Alignment.center,
                                        decoration: new BoxDecoration(
                                            color: yali==1?Colors.green:Color.fromARGB(1,242, 241, 247),
                                            borderRadius: new BorderRadius.only(
                                                bottomRight: cir)),
                                        child: Text(
                                          "水柱",
                                          style:
                                          TextStyle(fontSize: 20, fontWeight: FontWeight.w800,color: yali==1?Colors.white70:MyTheme(context).getColor('colorBlack')),
                                        ),
                                      ),
                                      onTap: (){
                                        yali=1;
                                        setState(() {

                                        });
                                      },
                                    ),
                                  ),
                                ],
                              )),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
            Positioned(
              width: ScreenAdapter.width(750),
                bottom: 50,
                child: Container(
                  height:  ScreenAdapter.height(90),
                  child: Row(
                    children: [
                      Expanded(
                        child: InkWell(
                          child: Container(
                            color: MyTheme(context).getColor("white"),
                            child: Center(
                              child: Text(
                                "重置",
                                style: new TextStyle(fontSize: 25.0,color:MyTheme(context).getColor('text_color')),
                              ),
                            ),
                          ),
                          onTap: () {
                            setState(() {
                              tiji=0;
                              weights=0;
                              hot=0;
                              yali=0;
                            });
                          },
                        ),
                      ),
                      Expanded(
                        child: GestureDetector(
                          child:   Container(
                            color: Colors.green,
                            child: Center(
                              child: Text(
                                "提交",
                                style: new TextStyle(fontSize: 25.0,color: Colors.white),
                              ),
                            ),
                          ),
                          onTap: () async{
                            SharedPreferences prefs = await SharedPreferences.getInstance();
                            prefs.setInt("tiji", tiji);
                            prefs.setInt("weights", weights);
                            prefs.setInt("hot", hot);
                            prefs.setInt("yali", yali);
                            Fluttertoast.showToast(msg: "提交成功");
                            setState(() {

                            });
                          },
                        ),
                      )
                    ],
                  ),
                ),)
          ],
        ),
      )


    );
  }
}


